package com.example.springboot.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
 * 接口统一返回的包装类
 * */
@Data
//无参构造
@NoArgsConstructor
//有参构造
@AllArgsConstructor
public class Result {
    private String code; //请求
    private String msg; //请求失败原因
    private Object data; //数据
    //有数据的成功
    public static Result success(Object data){
        return new Result(Constants.CODE_200,"",data);
    }

    //没有数据的成功
    public static Result success(){
        return new Result(Constants.CODE_200,"",null);
    }

    //有数据错误
    public static Result error(String code, String msg){
        return new Result(code,msg,null);
    }

    //错误
    public static Result error(){
        return new Result(Constants.CODE_500,"系统错误",null);
    }

}
